package com.wgc.oauth.service.impl;

import com.wgc.oauth.mapper.UserMapper;
import com.wgc.oauth.pojo.SysUser;
import com.wgc.oauth.service.UserService;
import com.wgc.user.domain.User;
import com.wgc.user.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {
//    @Autowired
//    private UserMapper userMapper;
@Autowired
public UserFeign  userFeign;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
     try {
            User user = new User();
            user.setUsername(username);
            User user1 = userFeign.select(user).getData().get(0);
            SysUser sysUser = new SysUser();
            sysUser.setUsername(user1.getUsername());
            sysUser.setPassword(user1.getPassword());
            sysUser.setId(user1.getId());
            sysUser.setStatus(user1.getStatus());
            sysUser.setRoles(user1.getRole());
            return sysUser;
        }catch (Exception e){
         return null;
     }
    }

}

